package com.example.librarymanagementsystem.controller;

import com.example.librarymanagementsystem.model.BookInfo;
import com.example.librarymanagementsystem.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/5/10 13:45
 */
@CrossOrigin
@RestController
@RequestMapping("/admin")
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/selectAll")
    public List<BookInfo> selectAll(BookInfo bookInfo) {
        return bookService.selectAll(bookInfo);
    }

    @PostMapping("/selectBook")
    public List<BookInfo> selectBook(@RequestBody BookInfo bookInfo) {
        return bookService.selectAll(bookInfo);
    }

    @GetMapping("/countNum")
    public Integer countNum() {
        return bookService.countNum();
    }

    @PostMapping("/insert")
    public Integer insertBook(@RequestBody BookInfo bookInfo) {
        System.out.println(bookInfo.toString());
        return bookService.insertBook(bookInfo);
    }

    @RequestMapping("/update")
    public Integer updateBook(@RequestBody BookInfo bookInfo) {
        return bookService.updateBook(bookInfo);
    }

    @PostMapping("/delete")
    public Integer deleteBook(@RequestBody BookInfo bookInfo) {
        return bookService.deleteBook(bookInfo);
    }

    @PostMapping("/deletelist")
    public Integer deleteList(@RequestBody List<BookInfo> ids) {
        return bookService.deleteBookByList(ids);
    }


}
